<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // const url = 'https://www.imooc.com/api/http/search/suggest?words=js';
    const url = 'https://www.imooc.com/api/http/json/search/suggest?words=js';
    const xhr = new XMLHttpRequest
    xhr.onreadystatechange = () => {
      if (xhr.readyState !== 4) return;
      if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
        console.log(xhr.responseText);
        console.log(typeof xhr.responseText);
      }
    }
    // xhr.open('GET', url, true)
    xhr.open('POST', url, true)
    //设置请求头信息
    //告诉服务器，浏览器发送的数据是什么格式的
    // xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
    xhr.setRequestHeader('Content-Type','application/json')
    // xhr.send(null)
    xhr.send(JSON.stringify({name:'a'}))
    //终止当前请求
    // xhr.abort()
  </script>
</body>
</html>